package com.roncoo.education.course.service.admin;

import com.roncoo.education.common.config.ThreadContext;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.course.service.admin.biz.AdminSphereBiz;
import com.roncoo.education.course.service.admin.req.AdminSphereEditReq;
import com.roncoo.education.course.service.admin.req.AdminSpherePageReq;
import com.roncoo.education.course.service.admin.req.AdminSphereSaveReq;
import com.roncoo.education.course.service.admin.resp.AdminSpherePageResp;
import com.roncoo.education.course.service.admin.resp.AdminSphereViewResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * ADMIN-全景信息
 *
 * @author wujing
 */
@Api(tags = "ADMIN-全景信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/course/admin/sphere")
public class AdminSphereController {

    @NotNull
    private final AdminSphereBiz biz;

    @ApiOperation(value = "全景信息分页", notes = "全景信息分页")
    @PostMapping(value = "/page")
    public Result<Page<AdminSpherePageResp>> page(@RequestBody AdminSpherePageReq req) {
        return biz.page(req, ThreadContext.userId());
    }

    @ApiOperation(value = "全景信息添加", notes = "全景信息添加")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminSphereSaveReq req) {
        return biz.save(req, ThreadContext.userId());
    }

    @ApiOperation(value = "全景信息查看", notes = "全景信息查看")
    @ApiImplicitParam(name = "id", value = "主键ID", dataTypeClass = Long.class, paramType = "query", required = true)
    @GetMapping(value = "/view")
    public Result<AdminSphereViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @ApiOperation(value = "全景信息修改", notes = "全景信息修改")
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminSphereEditReq req) {
        return biz.edit(req);
    }

    @ApiOperation(value = "全景信息删除", notes = "全景信息删除")
    @ApiImplicitParam(name = "id", value = "主键ID", dataTypeClass = Long.class, paramType = "query", required = true)
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }
    
    @ApiOperation(value = "ES同步全景", notes = "将全景同步到ES")
    @GetMapping(value = "/es")
    public Result<String> syncEs() {
    	try {
    		biz.syncEs();
    		return Result.success("全景同步成功");
    	} catch (Exception e) {
			e.printStackTrace();
			return Result.error("全景同步失败： " + e.getMessage());
		}
    }    
}
